﻿using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Shinva.Variables.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shinva.Variables.Interface
{
   public abstract class PlcMemberBase :ReactiveUI.ReactiveObject, IPlcMember
    {
        private string _value;

        //变量名称
        public string Name { get; set; } = "PlcMemberBase";
        //变量全名
        public string FullName { get; set; }
        //变量符号
        public string Symbol { get; set; }
        //数据类型
        public DataType DataType { get; set; }
        //变量地址偏移量
        public PlcAddress Address { get; set; } = new PlcAddress(0, 0);
        //占用位数
        public int SizeInBits { get; set; }

        //上一级变量
        public IPlcMember Parent { get; set; }
        public string Value
        {
            get => _value;
            set => this.RaiseAndSetIfChanged(ref _value, value);
        }
        /// <summary>
        /// 根据占用位数计算占用字节数
        /// </summary>
        /// <returns></returns>
        public int SizeInBytes() => (SizeInBits + 7) / 8;

        public PlcMemberBase()
        {
        }
    }
 
}
